package demo1.servlet.all;

import com.alibaba.fastjson.JSON;
import demo1.pojo.goods;
import demo1.pojo.users;
import demo1.service.goodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/modifyGoods2")
public class modifyGoods2 extends HttpServlet {//添加session里面的goodsID到对象
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接受数据
        BufferedReader br = req.getReader();
        String params = br.readLine();//json字符串

        //转为goods对象
        goods goods= JSON.parseObject(params,goods.class);

        //获取session对象
        HttpSession session = req.getSession();
        Object userObject = session.getAttribute("users");
        users users = (users) userObject;

        users.setGoodsID(goods.getGoodsID());
        session.setAttribute("users", users);

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
